// implementation of the Queue data structure,  front node is at the   1st location followed by the next 2nd node , 3rd ..... in the end there is rear node

#include<iostream.h>
#include<conio.h>
#include"Node.h"

class Queue
{
      private:
              void enQueue(Node** rear, int value);
              int deQueue(Node**front);
              void display(Node *Q);
              void deleteQueue(Node **front);
      public:
             struct Node *front, *rear;
             Queue()
             {
                    front = NULL;
                    rear =  NULL;
             }
             void enQueue(int value);
             int deQueue();
             void display();
             bool isEmptyQueue();
             void deleteQueue();
};
void Queue :: deleteQueue(Node **front)
{
     Node *tempNode = *front, *deleteNode = *front;
     if(tempNode == NULL)
        return ;
     *front = tempNode->next;
     delete (deleteNode);
     deleteQueue(front);
     
}
void Queue :: deleteQueue()
{
     deleteQueue(&front);
}
bool Queue :: isEmptyQueue()
{
    return (front == NULL);    
}
int Queue :: deQueue(Node **front)
{
    if(front == NULL)
    {
        cout<<"\nQueue under flow";
        return -1;
    }
    Node *temp = *front;
    *front = temp->next;
    int value = temp->data;
    delete (temp);
    return value;
}
int Queue :: deQueue()
{
    return deQueue(&front);
}
void Queue :: enQueue(Node **rear, int value)
{
     Node *newNode = new Node(value);
     Node *tempNode = *rear;
     if(*rear == NULL)
     {
         *rear = newNode;
         front = newNode;
     }
     else
     {
          tempNode->next = newNode;
         tempNode = tempNode->next;
         *rear = tempNode;
     }
}
void Queue :: enQueue(int value)
{
     enQueue(&rear, value);
}
void Queue :: display(Node *front)
{
     if(front == NULL)
         return ;
     else
     {       
         Node * tempNode = front;
         if(tempNode == NULL)
            return ;
         else
         {
             while(tempNode != NULL)
             {
                 cout<<tempNode->data<<" ";
                 tempNode = tempNode->next;
             }
         }
         
     }
}
void Queue :: display()
{
     display(front);
}

int main()
{
    Queue Q;
    Q.enQueue(3);
    Q.enQueue(5);
    Q.enQueue(7);

//    Q.enQueue(33);
//    Q.enQueue(15);
//    Q.enQueue(73);
    Q.display();
   
    int value = Q.deQueue();
    cout<<"\n";
    Q.display();
   
    //value = Q.deQueue();
//    cout<<"\n";
//    Q.display();
   
    cout<<"\nisQueue empty "<< Q.isEmptyQueue();
    
    Q.deleteQueue();
    cout<<"\nisQueue empty "<< Q.isEmptyQueue();
    getch();
    return 0;   
}

